package org.zero.db;

import lombok.experimental.UtilityClass;

import java.lang.reflect.Proxy;

/**
 * @author Zero
 */
@UtilityClass
public class TransactionProxyFactory {

    public static Object getTransactionManagerProxy(Object target) {
        return Proxy.newProxyInstance(target.getClass().getClassLoader(),
                target.getClass().getInterfaces(),
                new TransactionProxy(target));
    }

    public static <T> T getTransactionManagerProxy(Object target, Class<T> type) {
        return type.cast(Proxy.newProxyInstance(target.getClass().getClassLoader(),
                target.getClass().getInterfaces(),
                new TransactionProxy(target)));
    }
}
